﻿<span style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>Protected</span> <span style='color:#800000; font-weight:bold; '>Sub</span> convertToPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> sender <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Object</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> e <span style='color:#800000; font-weight:bold; '>As</span> EventArgs<span style='color:#808030; '>)</span>
    <span style='color:#696969; '>' Create a HTML to PDF converter object with default settings</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> htmlToPdfConverter <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfConverter<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>' Leave it not set to use the converter in demo mode</span>
    htmlToPdfConverter<span style='color:#008c00; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#0000e6; '>"4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="</span>

    <span style='color:#696969; '>' Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed</span>
    <span style='color:#696969; '>' Set this property to 0 if you don't need to wait for such asynchcronous operations to finish</span>
    htmlToPdfConverter<span style='color:#008c00; '>.</span>ConversionDelay <span style='color:#808030; '>=</span> <span style='color:#008c00; '>2</span>

    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfDocument <span style='color:#800000; font-weight:bold; '>As</span> Document <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>Nothing</span>
    <span style='color:#800000; font-weight:bold; '>Try</span>
        <span style='color:#696969; '>' Convert HTML page or string with mapping attributes to a PDF document object </span>
        <span style='color:#696969; '>' The document can be further modified to highlight the selected elements</span>
        <span style='color:#800000; font-weight:bold; '>If</span> convertHtmlRadioButton<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlWithMappingAttributes <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlStringTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span>
            <span style='color:#800000; font-weight:bold; '>Dim</span> baseUrl <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> baseUrlTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span>

            <span style='color:#696969; '>' Convert a HTML string with mapping attributes to a PDF document object</span>
            pdfDocument <span style='color:#808030; '>=</span> htmlToPdfConverter<span style='color:#008c00; '>.</span>ConvertHtmlToPdfDocumentObject<span style='color:#808030; '>(</span>htmlWithMappingAttributes<span style='color:#808030; '>,</span> baseUrl<span style='color:#808030; '>)</span>
        <span style='color:#800000; font-weight:bold; '>Else</span>
            <span style='color:#800000; font-weight:bold; '>Dim</span> url <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> urlTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span>

            <span style='color:#696969; '>' Convert a HTML page with mapping attributes to a PDF document object</span>
            pdfDocument <span style='color:#808030; '>=</span> htmlToPdfConverter<span style='color:#008c00; '>.</span>ConvertUrlToPdfDocumentObject<span style='color:#808030; '>(</span>url<span style='color:#808030; '>)</span>
        <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

        <span style='color:#696969; '>' Display detailed information about the selected elements</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementInfoBuilder <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> StringBuilder<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
        <span style='color:#800000; font-weight:bold; '>For</span> <span style='color:#800000; font-weight:bold; '>Each</span> htmlElementInfo <span style='color:#800000; font-weight:bold; '>As</span> HtmlElementMapping <span style='color:#800000; font-weight:bold; '>In</span> htmlToPdfConverter<span style='color:#008c00; '>.</span>HtmlElementsMappingOptions<span style='color:#008c00; '>.</span>HtmlElementsMappingResult
            <span style='color:#696969; '>' Get other information about HTML element</span>
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementTagName <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementTagName
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementID <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementId
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementMappingID <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>MappingId
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementCssClasssName <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementCssClassName
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementHtmlCode <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementOuterHtml
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementInnerHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementInnerHtml
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementText <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementText
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementAttributes <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>System</span><span style='color:#008c00; '>.</span>Collections<span style='color:#008c00; '>.</span>Specialized<span style='color:#008c00; '>.</span>NameValueCollection <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>HtmlElementAttributes
            <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementRectanglesInPdf<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>As</span> HtmlElementPdfRectangle <span style='color:#808030; '>=</span> htmlElementInfo<span style='color:#008c00; '>.</span>PdfRectangles

            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;br/>---------------------------------------- HTML Element Info ----------------------------------------&lt;br/>&lt;br/>"</span><span style='color:#808030; '>)</span>
            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Tag Name:&lt;/b> {0}&lt;br/>"</span><span style='color:#808030; '>,</span> htmlElementTagName<span style='color:#808030; '>)</span>
            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Element ID:&lt;/b> {0}&lt;br/>"</span><span style='color:#808030; '>,</span> htmlElementID<span style='color:#808030; '>)</span>
            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Mapping ID:&lt;/b> {0}&lt;br/>"</span><span style='color:#808030; '>,</span> htmlElementMappingID<span style='color:#808030; '>)</span>
            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Text:&lt;/b> {0}&lt;br/>"</span><span style='color:#808030; '>,</span> htmlElementText<span style='color:#808030; '>)</span>

            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Attributes:&lt;/b>&lt;br/>"</span><span style='color:#808030; '>)</span>
            <span style='color:#800000; font-weight:bold; '>For</span> i <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Integer</span> <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span> <span style='color:#800000; font-weight:bold; '>To</span> htmlElementAttributes<span style='color:#008c00; '>.</span>Count <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span>
                htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&amp;nbsp;&amp;nbsp;&amp;nbsp;{0} = "</span><span style='color:#0000e6; '>"{1}"</span><span style='color:#0000e6; '>"&lt;br/>"</span><span style='color:#808030; '>,</span> htmlElementAttributes<span style='color:#008c00; '>.</span>GetKey<span style='color:#808030; '>(</span>i<span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> htmlElementAttributes<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Get</span><span style='color:#808030; '>(</span>i<span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>
            <span style='color:#800000; font-weight:bold; '>Next</span> i


            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;b>Location in PDF:&lt;/b>&lt;br/>"</span><span style='color:#808030; '>)</span>
            <span style='color:#800000; font-weight:bold; '>For</span> i <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Integer</span> <span style='color:#808030; '>=</span> <span style='color:#008c00; '>0</span> <span style='color:#800000; font-weight:bold; '>To</span> htmlElementRectanglesInPdf<span style='color:#008c00; '>.</span>Length <span style='color:#808030; '>-</span> <span style='color:#008c00; '>1</span>
                <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPage <span style='color:#800000; font-weight:bold; '>As</span> PdfPage <span style='color:#808030; '>=</span> htmlElementRectanglesInPdf<span style='color:#808030; '>(</span>i<span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>PdfPage
                <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPageIndex <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Integer</span> <span style='color:#808030; '>=</span> htmlElementRectanglesInPdf<span style='color:#808030; '>(</span>i<span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>PageIndex
                <span style='color:#800000; font-weight:bold; '>Dim</span> rectangleInPdfPage <span style='color:#800000; font-weight:bold; '>As</span> RectangleF <span style='color:#808030; '>=</span> htmlElementRectanglesInPdf<span style='color:#808030; '>(</span>i<span style='color:#808030; '>)</span><span style='color:#808030; '>.</span>Rectangle

                htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&amp;nbsp;&amp;nbsp;&amp;nbsp;PDF Page Index: {0}&lt;br>"</span><span style='color:#808030; '>,</span> pdfPageIndex<span style='color:#808030; '>)</span>
                htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&amp;nbsp;&amp;nbsp;&amp;nbsp;Rectangle: X = {0:N2} pt , Y = {1:N2} pt , W = {2:N2} pt , H = {3:N2} pt&lt;br/>"</span><span style='color:#808030; '>,</span> rectangleInPdfPage<span style='color:#008c00; '>.</span>X<span style='color:#808030; '>,</span> rectangleInPdfPage<span style='color:#008c00; '>.</span>Y<span style='color:#808030; '>,</span> rectangleInPdfPage<span style='color:#008c00; '>.</span>Width<span style='color:#808030; '>,</span> rectangleInPdfPage<span style='color:#008c00; '>.</span>Height<span style='color:#808030; '>)</span>
            <span style='color:#800000; font-weight:bold; '>Next</span> i

            htmlElementInfoBuilder<span style='color:#008c00; '>.</span>AppendFormat<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"&lt;br/>"</span><span style='color:#808030; '>)</span>
        <span style='color:#800000; font-weight:bold; '>Next</span> htmlElementInfo

        <span style='color:#800000; font-weight:bold; '>Dim</span> lastPdfPage <span style='color:#800000; font-weight:bold; '>As</span> PdfPage <span style='color:#808030; '>=</span> htmlToPdfConverter<span style='color:#008c00; '>.</span>ConversionSummary<span style='color:#008c00; '>.</span>LastPdfPage
        <span style='color:#800000; font-weight:bold; '>Dim</span> lastPageRectangle <span style='color:#800000; font-weight:bold; '>As</span> RectangleF <span style='color:#808030; '>=</span> htmlToPdfConverter<span style='color:#008c00; '>.</span>ConversionSummary<span style='color:#008c00; '>.</span>LastPageRectangle

        <span style='color:#800000; font-weight:bold; '>Dim</span> htmlElementInfoHtml <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span><span style='color:#008c00; '>0</span><span style='color:#808030; '>,</span> lastPageRectangle<span style='color:#008c00; '>.</span>Bottom <span style='color:#808030; '>+</span> <span style='color:#008c00; '>1</span><span style='color:#808030; '>,</span> htmlElementInfoBuilder<span style='color:#008c00; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>Nothing</span><span style='color:#808030; '>)</span>
        lastPdfPage<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>htmlElementInfoHtml<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Save the PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> outPdfBuffer<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Byte</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Save<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Send the PDF as response to browser</span>

        <span style='color:#696969; '>' Set response content type</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Type"</span><span style='color:#808030; '>,</span> <span style='color:#0000e6; '>"application/pdf"</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Instruct the browser to open the PDF file as an attachment or inline</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Disposition"</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>String</span><span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Format</span><span style='color:#808030; '>(</span><span style='color:#0000e6; '>"attachment; filename=Select_in_HTML_Elements_to_Retrieve.pdf; size={0}"</span><span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#008c00; '>.</span>Length<span style='color:#008c00; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Write the PDF document buffer to HTTP response</span>
        Response<span style='color:#008c00; '>.</span>BinaryWrite<span style='color:#808030; '>(</span>outPdfBuffer<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' End the HTTP response and stop the current page processing</span>
        Response<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>End</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Finally</span>
        <span style='color:#696969; '>' Close the PDF document</span>
        <span style='color:#800000; font-weight:bold; '>If</span> pdfDocument IsNot <span style='color:#800000; font-weight:bold; '>Nothing</span> <span style='color:#800000; font-weight:bold; '>Then</span>
            pdfDocument<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Close</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
        <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Try</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>
</pre>
</span>